package com.woniu.service;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.woniu.entity.Finance;
import com.woniu.entity.Order;
import com.woniu.model.Funds;
import com.woniu.model.QueryVo;
import com.woniu.utils.PageUtil;
import com.woniu.dao.FinanceMapper;

@Transactional
@Service
public class FinanceService {
	@Autowired
	private FinanceMapper financeMapper;

	public FinanceMapper getFinanceMapper() {
		return financeMapper;
	}
	
	public PageUtil selectAllByIdAnduNameAndTime(String orderGenerateId, String buyUserName, Date startTime,
			Date endTime, int pageSize, int pageNum) {
		PageUtil pageList = new PageUtil();
		pageList.setPageNum(pageNum);
		pageList.setPageSize(pageSize);
		
		//endTime+1
		
		int count = financeMapper.selectCountByIdAnduNameAndTime(orderGenerateId, buyUserName, startTime, endTime);
		List<QueryVo> vo = financeMapper.selectAllByIdAnduNameAndTime(orderGenerateId, buyUserName, startTime, endTime,
				pageList.getPageSize(), pageList.getStartNum());
		return new PageUtil(count, pageNum, vo, pageSize);
	}

	public Funds selectFunds(Date startTime, Date endTime) {
		return financeMapper.selectFunds(startTime, endTime);
	}

	/**
	 * @return
	 */
	public List<Order> selectOrderList() {		
		return financeMapper.selectOrderList();
	}

	/**
	 * @param ordergenerateid
	 * @param gid
	 * @param dealtime
	 * @param dealprice
	 * @param commission
	 * @param totalrevenue
	 * @param uBid
	 * @param sSid
	 * @param paymentchannel
	 */
	public void insertFinance(String ordergenerateid, Integer gid, Date dealtime, double dealprice, double commission,
			double totalrevenue, Integer uBid, Integer sSid, String paymentchannel) {
		Finance finance = new Finance();
		finance.setOrdergenerateid(ordergenerateid);
		finance.setGid(gid);
		finance.setDealtime(dealtime);
		finance.setDealprice(dealprice);
		finance.setCommission(commission);
		finance.setTotalrevenue(totalrevenue);
		finance.setuBid(uBid);
		finance.setsSid(sSid);
		finance.setPaymentchannel(paymentchannel);
		financeMapper.insert(finance);
	}

	
}